package com.github.zxhTom.demo.jol.factory;

import java.util.*;

public class FactoryTest {
    public static void main(String[] args) {
        while (true){
            OnFactory.setInstance();
            List<Thread> threadList = new ArrayList<Thread>();
            final Map<OnFactory,Object> map = new Hashtable<OnFactory,Object>();
            for (int i = 0; i < 1000; i++) {
                Thread thread = new Thread(new Runnable() {
                    public void run() {
                        final OnFactory instance = OnFactory.getInstance();
//                    System.out.println(instance);
                        map.put(instance, instance.getAge().toString());
                    }
                });
                thread.start();
                threadList.add(thread);
            }
            for (Thread thread : threadList) {
                try {
                    thread.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            if (map.size() > 1) {
                System.out.println(map.size());
            }
        }
    }
}
